<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\web\View;

/* @var $this yii\web\View */
/* @var $searchModel app\models\MaterialborrowSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '物资借用';
$this->params['breadcrumbs'][] = $this->title;
$js=<<< Js
var exportLink = document.getElementById('export');
	exportLink.addEventListener('click', function(e){
		e.preventDefault();
		if(e.target.nodeName === "A"){
			tableExport('table-export', '导出文件', e.target.getAttribute('data-type'));
		}

	}, false);
Js;
$this->registerJs($js, View::POS_END, 'myAjax');
?>
<script src="<?= \Yii::getAlias('@web')?>/js/Blob.js"></script>
<script src="<?= \Yii::getAlias('@web')?>/js/FileSaver.js"></script>
<script src="<?= \Yii::getAlias('@web')?>/js/tableExport.js"></script>

<div class="materialborrow-model-index">

   
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加', ['create'], ['class' => 'btn btn-success']) ?>
         <div id="export" ><a class="btn btn-info"  data-type="xls" href="javascript:;">导出excel</a></div>	
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
    		'tableOptions'=>[
    				'id'=>'table-export',
    				'class' => 'table table-striped table-bordered',
    		],
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'stu_id',
            'stu_name',
            'activitytitle',
            'material',
            'telephone',
            'time',
            'approved',
            'remark',

            [
            	'class' => 'yii\grid\ActionColumn',
            	'header' => '操作',
            	'template' => '{agree}{disagree}{view}{delete}',
            	'buttons' => 
            		[
            			'agree' => function ($url,$model, $key) {
            			return $model->approved=='审批中'?Html::a('<button>同意</button> ', '/bnews/web/materialborrow/agree?id='.$model->id,['title' => '同意'] ):'';
            			},
            			'disagree' => function ($url,$model, $key) {
            			return $model->approved=='审批中'?Html::a(' <button>不同意</button> ', '/bnews/web/materialborrow/disagree?id='.$model->id, ['title' => '不同意'] ):'';
            			},
                        'view' => function ($url,$model, $key) {
                            return Html::a('<button>详情</button> ', '/bnews/web/materialborrow/view?id='.$model->id,['title' => '详情'] );
                        },
                        'delete' => function ($url,$model, $key) {
                            return Html::a(' <button>删除</button> ', '/bnews/web/materialborrow/delete?id='.$model->id, ['title' => '删除'] );
                        },
            		],
             			'headerOptions' => ['width' => '220'],
            		
    		],
        ],
    ]); ?>
</div>
